package com.mach.platform.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
import com.github.pagehelper.PageInfo;
import com.mach.platform.domain.IotDevImportModel;
import com.mach.platform.domain.Response;
import com.mach.platform.domain.iot.*;
import com.mach.platform.innotation.EMSCache;
import com.mach.platform.service.IotDevServiceImpl;
import com.mach.platform.service.js.iot.*;
import com.mach.platform.utils.Utils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @Description: 设备库控制器
 * @Package: com.mach.platform.controller
 * @time 2018/4/26 0026 15:21
 */
@Slf4j
@Api(tags = {"设备接口"})
@RestController
@RequestMapping("/iot/dev")
public class IotDevCtrl extends BaseCtrl<IotDev> {

    @Autowired
    private IOTVirDevService virService;

    @Autowired
    private IotDevServiceImpl iotDevService;

    @Autowired
    private IOTJsService iotJsService;

    // 设备编号和属性名称匹配规则
    private String regex = "^[a-zA-Z|_]([\\u4e00-\\u9fa5\\w]{1,50})$";
    private String snMessage = "设备编号只能以英文字母，数字，中文，下划线编写，并且只能以英文字母或者下划线开头，不允许出现特殊字符";
    private String itemMessage = "设备属性名称只能以英文字母，数字，中文，下划线编写，并且只能以英文字母或者下划线开头，不允许出现特殊字符";


//    @PostMapping("/insert2019AfterFactoryData")
//    public Response insert2019AfterFactoryData() {
//        Integer[] devIds = {11167, 11131, 11083, 11005, 301}; // 工厂成本表设备id
//        iotDevService.insert2019AfterFactoryData("成本", devIds, "cost");
//        return Response.ok();
//    }


//    @PostMapping("/insert2019AfterWorkShopData")
//    public Response insert2019AfterWorkShopData() {
//        iotDevService.insert2019AfterWorkData();
//        return Response.ok();
//    }


    /**
     * -- @GetMapping(value = "/info/{id}")
     * -- @ApiOperation(value = "单个实体信息", notes = "接口备注：无", produces = "application/json")
     * 单个数据 的接口
     * -- @PathVariable(value = "id", required = true) Long id
     *
     * @param id 数据的id
     * @return Response
     */

    @ApiOperation(value = "查询单个实体", notes = "单实例数据查询", produces = "application/json")
    @GetMapping(value = "/info")
    @Override
    public Response info(Long id) {
        IotDev result = iotDevService.info(id);
        return Response.ok(result);
    }

    /**
     * --	@ApiOperation(value = "列表--分页", produces = "application/json", notes = "列表参数：size(每页数量),page(页码),searchParam(查询内容)")
     * -- @GetMapping(value = "/xxxs")
     * 获取列表数据
     * -- @PageableDefault(size = 25) Pageable pageable
     * -- @RequestParam Map params
     *
     * @param pageable 分页参数
     * @param params   其他参数
     * @return Response
     */
//    @Cacheable(value = "iotDev", key = "'dev_'+#params.get('keyword')+'_'+#pageable.pageNumber+'_'+#pageable.pageSize")
    @ApiOperation(value = "列表--分页", produces = "application/json", notes = "列表参数：size(每页数量),page(页码),searchParam(查询内容)")
    @GetMapping(value = "/list")
    @Override
    public Response list(@PageableDefault(size = 50, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, @RequestParam Map params) {
        String keyword = params.get("keyword").toString().trim();
        if (!keyword.isEmpty() && Utils.isNumeric(keyword)) {
            params.put("id_eq", Long.parseLong(keyword));
        } else {
            params.put("iotDevType.brand_sn_name_commAddr_iotDevType.useType_iotSpace.name_plike", keyword);
        }
        params.remove("keyword");
        Page<IotDev> dbResult = iotDevService.list(pageable, params);
        return Response.ok(dbResult);
    }

    @GetMapping(value = "/listt")
    public Response listt(@PageableDefault(size = 50, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, @RequestParam Map params) {
        String keyword = params.get("keyword").toString().trim();
        if (!keyword.isEmpty() && Utils.isNumeric(keyword)) {
            params.put("id_eq", Long.parseLong(keyword));
        } else {
            params.put("iotDevType.brand_sn_name_commAddr_iotDevType.useType_iotSpace.name_plike", keyword);
        }
//        params.put("type_nin", "2");
        params.remove("keyword");
        Page<IotDev> dbResult = iotDevService.list(pageable, params);
        return Response.ok(dbResult);
    }

    /**
     * -- @DeleteMapping("/del")
     * -- @ApiOperation(value = "删除", notes = "接口备注：无", produces = "application/json")
     * 删除数据
     * -- @RequestBody Long[] ids
     *
     * @param ids id的集合
     * @return Response
     */
    @CacheEvict(value = "iotDev", allEntries = true)
    @ApiOperation(value = "删除", notes = "接口备注：无", produces = "application/json")
    @DeleteMapping("/del")
    @Override
    public Response delete(@RequestBody Long[] ids) {

        Integer nums = iotDevService.delete(ids);

        return Response.ok(nums);
    }

    /**
     * --@PostMapping("/save")
     * --	@ApiOperation(value = "保存", notes = "接口备注：无", produces = "application/json")
     * 保存一个 对象
     * --@RequestBody T t
     *
     * @param device 保存的实体
     * @return Response
     */
    @CacheEvict(value = "iotDev", allEntries = true)
    @ApiOperation(value = "保存", notes = "接口备注：无", produces = "application/json")
    @PostMapping("/save")
    @Override
    public Response save(@RequestBody IotDev device) {
        Response inspectNumberResp = this.inspectNumber(device.getSn(), device.getId());
        if (inspectNumberResp.getStatus() != 200) {
            return inspectNumberResp;
        }
        Response response = checkIotDevice(device);
        if (response.getStatus() != 200) {
            return response;
        }
        return Response.ok(iotDevService.save(device));
    }

    @ApiOperation(value = "检查编号", notes = "接口备注：无")
    @PostMapping("/inspectNumber")
    public Response inspectNumber(String sn, Long id) {
        boolean result = iotDevService.inspectNumber(sn, id);
        if (result == true) {
            return Response.error("该编号已存在");
        }
        return Response.ok("可以使用");
    }

    /**
     * --@PutMapping("/upd")
     * --	@ApiOperation(value = "更新", notes = "接口备注：无", produces = "application/json")
     * 更新一个对象
     * --@RequestBody T t
     *
     * @param device 更新的实体
     * @return Response
     */
    @CacheEvict(value = "iotDev", allEntries = true)
    @ApiOperation(value = "更新", notes = "接口备注：无", produces = "application/json")
    @PutMapping("/upd")
    @Override
    public Response update(@RequestBody IotDev device) {
        Response inspectNumberResp = this.inspectNumber(device.getSn(), device.getId());
        if (inspectNumberResp.getStatus() != 200) {
            return inspectNumberResp;
        }
        Response response = checkIotDevice(device);
        if (response.getStatus() != 200) {
            return response;
        }
        IotDev iotDev = iotDevService.update(device);
        return Response.ok(iotDev);
    }


    /**
     * 验证非组合设备编号和属性名称是否符合规则
     * @param device
     * @return
     */
    public Response checkIotDevice(IotDev device) {
        if (device.getType() != 2) {
            if (!device.getSn().matches(regex)) {
                return Response.error(snMessage);
            }
//            List<IotVirtualItem> virtualItems = device.getVirtualItems();
//            for (IotVirtualItem item : virtualItems) {
//                if (!item.getName().matches(regex)) {
//                    return Response.error(itemMessage);
//                }
//            }
        }
        return Response.ok();
    }


    /**
     * 根据空间id获取 关联的设备数据
     *
     * @param iotSpace 空间id
     * @return
     */
    @ApiOperation(value = "根据空间id获取所有绑定到其上的设备数据", notes = "接口备注：传入一个必须包含空间id的 对象{id: 空间id} 到 requestbody", produces = "application/json")
    @RequestMapping(value = "/sid", method = RequestMethod.POST)
    public Response loadDevsBySpaceId(@RequestBody IotSpace iotSpace) {

        List<IotDev> iotDevs = iotDevService.LoadAllDevsByIotSpace(iotSpace);

        return Response.ok(iotDevs);
    }

    /**
     * 实时数据
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "查询单个设备数据", notes = "设备数据查询", produces = "application/json")
    @PostMapping(value = "/curData")
    public Response curData(@RequestParam HashMap<String, Object> param) {
        Long id = null;
        if (param.get("id") == null) {
            return Response.error("参数：设备id 为空");
        } else {
            id = Long.parseLong(param.get("id").toString());
        }
        return curData(id, param);
    }



    /**
     * 实时数据
     *
     * @param param
     * @return
     */
//    @EMSCache
    @ApiOperation(value = "查询单个设备数据", notes = "设备数据查询", produces = "application/json")
    @PostMapping(value = "/curData/{id}")
    public Response curData(@RequestParam Long id, @RequestParam HashMap<String, Object> param) {
        if (id == null) {
            if (param.get("id") == null) {
                return Response.error("参数：设备id 为空");
            } else {
                id = Long.parseLong(param.get("id").toString());
            }
        }
        IotDev result = iotDevService.curData(id);
        GeneralModelDev modelDev = ModelDevFactory.getById(id.intValue());
        Response respObj = Response.ok(result);
        if (null != modelDev && null != id && param.size() > 1) {
            try {
                modelDev.sendAction(respObj, param);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return respObj;
    }


    /**
     * 查询设备属性数据
     * @param devId 设备id
     * @param type  属性类型
     * @param time  查询时间
     * @return
     */
    @ApiOperation(value = "查询设备属性数据", notes = "设备属性查询", produces = "application/json")
    @PostMapping("/devItemData")
    public Response devItemData(Long devId, String type, String time) throws ParseException {
        Map<String, Object> mapData = iotDevService.devItemData(devId, type, time);
        return Response.ok(mapData);
    }


    /**
     * 下载Excel设备属性数据
     * @param devId 设备id
     * @param type  属性类型
     * @param time  查询时间
     * @return
     */
    @PostMapping("/downDevItemData")
    public void downDevItemData(HttpServletResponse response, Long devId, String type, String time) throws ParseException, IOException {
        IotDev iotDev = iotDevService.getIotDevById(devId);
        List data = iotDevService.getDevItemData(iotDev, type, time);
        XSSFWorkbook workbook = iotDevService.createItemDataExcel(data, time);
        // Excel下载的相关配置
        response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(iotDev.getName(), "UTF-8") + "设备属性数据.xlsx");
        response.setContentType("application/vnd.ms-excel; charset=UTF-8");
        OutputStream outputStream = response.getOutputStream();
        workbook.write(outputStream);
        outputStream.flush();
        outputStream.close();
    }


    /**
     * 实时数据(最近N长时间)
     *
     * @param id
     * @return
     * @ApiParam(name="devID",value="设备id")
     * @ApiParam(name="dayCnt",value="查询的天数")
     * @ApiParam(name="timeLevel",value="查询粒度:1--秒，2--分，3--时，4--天，5--月，6--年") dataType 数据类型
     */
    @ApiOperation(value = "查询单个设备数据近段时间数据", notes = "设备数据查询", produces = "application/json")
    @PostMapping(value = "/realData")
    public Response realData(Long id,  Integer timeLevel, String dataType,String startTime,String endTime) {

        IotDev result = iotDevService.realData(id, timeLevel, dataType,startTime,endTime);

        List<Object> collItems = result.getIotCollItemDatas();

        for (Object item : collItems) {
            IotCollItemData collItem = (IotCollItemData) item;
            HashMap<String, Object> valueMap = (HashMap<String, Object>) collItem.getValue();
            valueMap.put("xaxis", valueMap.get("theTimes"));
            valueMap.remove("theTimes");
            valueMap.put("yaxis", valueMap.get("values"));
            valueMap.remove("values");
        }

        return Response.ok(result);
    }

    @ApiOperation(value = "系统部组态,实时数据请求", notes = "实时数据请求", produces = "application/json")
    @PostMapping("sysReal")
    public Response sysImgRealData(@RequestParam("uuid") String uuid) {
        List<Map> dbResult = iotDevService.sysImgRealData(uuid);
        return Response.ok(dbResult);
    }

    @ApiOperation(value = "系统部组态,实时数据请求", notes = "实时数据请求", produces = "application/json")
    @PostMapping("cur")
    public Response simpleRealData(@RequestParam("id") Long id) {

        Map<Long, List<Map<String, Object>>> dbResult = iotDevService.simpleRealData(id);

        return Response.ok(dbResult);

    }

    @ApiOperation(value = "重置设备信息到处理引擎", notes = "重置设备信息到处理引擎,让处理引擎与抓取器更新设备情况与重启", produces = "application/json")
    @GetMapping("resetDevInfo")
    public Response resetDevInfo() {

        this.iotJsService.flushAndReload();

        return Response.ok();
    }


    @PostMapping("proReal")
    @ApiOperation(value = "单个属性实时数据请求", notes = "实时数据请求", produces = "application/json")
    public Response singlePropertyRealData(@RequestParam("devId") Long devId, @RequestParam("dataType") String dataType) {
        Map dbResult = iotDevService.singlePropertyRealData(devId, dataType);
        return Response.ok(dbResult);
    }

    @PostMapping("def")
    @ApiOperation(value = "获取设定值", notes = "实时数据请求", produces = "application/json")
    public Response loadDefaultValues(@RequestParam("devId") Long devId, @RequestParam(value = "name", required = false, defaultValue = "") String name) {

        List<Map> dbresult = iotDevService.loadDefaultValues(devId, name);

        return Response.ok(dbresult);
    }

    /**
     * 控制开关
     *
     * @param did 设备ID
     * @param pid 属性ID
     * @return
     */
    @ApiOperation(value = "控制开关", notes = "控制开关", produces = "application/json")
    @PostMapping(value = "/switch")
    public Response doSwitch(@RequestParam("did") Long did, @RequestParam("pid") Long pid,
                             @RequestParam("value") Integer value) {
        Integer ifEffectedFalg = iotDevService.doSwitch(did, pid, value);
        return Response.ok(ifEffectedFalg);
    }


    @ApiOperation(value = "查询单个设备数据(GET方法)", notes = "设备数据查询", produces = "application/json")
    @GetMapping(value = "/curDataGet")
    public Response curDataGet(Long id) {
        HashMap<String, Object> map = new HashMap();
        map.put("id", id);
        Response response = curData(id, map);
        return response;
    }

    @ApiOperation(value = "计算虚拟设备数据", notes = "计算虚拟设备数据")
    @GetMapping(value = "/calVirData")
    public Response calVirData(String startDate, String endDate) {

        virService.calData(startDate, endDate);
        return Response.ok();
    }

    /**
     * 查询某个空间下所有子级空间所关联的所有设备数据
     *
     * @param spaceId
     * @return
     */
    @ApiOperation(value = "查询某个空间下所有子级空间所关联的所有设备数据(GET方法)", notes = "设备数据查询", produces = "application/json")
    @PostMapping("/spaceAllDevs")
    public Response loadSpaceUnderAllDevices(Long spaceId) {

        List<IotDev> iotDevs = iotDevService.loadSpaceUnderAllDevices(spaceId);

        return Response.ok(iotDevs);
    }

    /**
     * 查询站房设备数据
     *
     * @param spaceId
     * @return
     */
    @ApiOperation(value = "查询站房设备数据", notes = "设备数据查询", produces = "application/json")
    @PostMapping("/sttDevs")
    public Response loadStationDevices(@RequestParam(required = true) Long spaceId, @RequestParam(required = false) String names) {

        Map dbResult = iotDevService.loadStationDevices(spaceId);

        return Response.ok(dbResult);

    }

    /**
     * 查询站房设备数据
     *
     * @param spaceId
     * @return
     */
    @ApiOperation(value = "查询站房设备数据", notes = "设备数据查询", produces = "application/json")
    @PostMapping("/getSpaceIdDevs")
    public Response loadStationDevices(@RequestParam(required = true) Long spaceId) {

        Map dbResult = iotDevService.loadStationDevices(spaceId);

        return Response.ok(dbResult);
    }

    @ApiOperation(value = "工艺监视下的设备说", notes = "设备数据查询", produces = "application/json")
    @PostMapping("/loadVisionDevs")
    public Response loadVisionDevs(@RequestParam(required = true) Long spaceId) {

        Map dbResult = iotDevService.loadVisionStationDevices(spaceId);

        return Response.ok(dbResult);
    }

    /**
     * 查询单个工厂的线路系统数据
     *
     * @param spaceCode 工厂代号
     * @param eneryType 能源类型: 水，电，燃气，冷量，压缩空气
     * @param dataCnt   数据数量
     * @return
     */
    @ApiOperation(value = "查询单个工厂的线路系统数据 ", notes = "查询单个工厂的线路系统数据 ", produces = "application/json")
    @PostMapping(value = "/curSysLineData")
    public Response curSysLineData(String spaceCode, String eneryType, Integer dataCnt) {
        Map<String, Object> result = Collections.EMPTY_MAP;

        result = iotDevService.curSysLineData(spaceCode, eneryType, dataCnt);


        return Response.ok(result);
    }

    /**
     * 查询单个工厂的行政系统数据
     *
     * @param spaceCode 工厂代号
     * @param eneryType 能源类型: 水，电，燃气，冷量，压缩空气
     * @param dataCnt   数据数量
     * @return
     */
    @ApiOperation(value = "查询单个工厂的线路系统数据 ", notes = "查询单个工厂的线路系统数据 ", produces = "application/json")
    @PostMapping(value = "/getAdminMeasureTreeData")
    public Response getAdminMeasureTreeData(String spaceCode, String eneryType, Integer dataCnt) {
        Map<String, Object> result = Collections.EMPTY_MAP;

        result = iotDevService.getAdminMeasureTreeData(spaceCode, eneryType);


        return Response.ok(result);
    }

    /**
     * 导入 excel 数据
     *
     * @param file
     * @return
     */
    @PostMapping("import")
    public Response importDevicesDatas(@RequestParam("file") MultipartFile file) {

        if (file == null) {
            return Response.error("上传文件不能为空！");
        }

        List<IotDevImportModel> result = null;
        int importDatas = 0;


        ImportParams importParams = new ImportParams();
        importParams.setTitleRows(0);

        try {
            result = ExcelImportUtil.importExcel(file.getInputStream(), IotDevImportModel.class, importParams);
            importDatas = iotDevService.importDatas(result);
        } catch (Exception e) {
            if (e.getCause() instanceof ExcelImportException) {
                return Response.error("转换中，数据类型出错，请检查该填数字的地方不能填中文：" + e.getMessage());
            }
        }
        return Response.ok(importDatas);
    }

    /**
     * 向设备提交控制指令
     *
     * @param devId 设备id
     * @param cmd   指令
     * @param param 参数
     * @return
     */
    @ApiOperation(value = "向设备提交控制指令", notes = "控制设备操作某个动作")
    @PostMapping(value = "/cmdById")
    public Response cmdById(Long devId,@RequestParam(required = false) String prop ,String cmd, String param) {

        Integer result = 1;

//        this.iotDevService.cmdDev(devId, cmd, param);

//		this.iotDevService.cmdDev(devId,cmd, param);
        try {

            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            return Response.ok(this.iotDevService.cmdDev(devId,cmd, param));
        }
//        return Response.ok(result);

    }


    /**
     * todo delete 模拟测试同步操作 scho
     *
     * @param devId
     * @param cmd
     * @param param
     * @return
     */
    @ApiOperation(value = "测试设备的发送命令", notes = "测试设备的发送命令")
    @PostMapping(value = "/cmdByIdd")
    public Response cmdByIdTest(Long devId, String cmd, String param) {

        Integer result = 1;
//		this.iotDevService.cmdDev(devId,cmd, param);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            return Response.ok(iotDevService.updateDeviceStatus(devId, cmd));
        }
//		return Response.ok(result);
    }

    /**
     * 查找 属性数据
     *
     * @return
     */
    @ResponseBody
    @PostMapping("virs")
    public Response findCollItem(@PageableDefault Pageable pageable, @RequestParam Map map) {
        PageInfo collItem = iotDevService.findCollItem(pageable, map);
        return Response.ok(collItem);
    }

    /**
     * 保存设备的参数
     *
     * @return
     */
    @ResponseBody
    @PostMapping("updParam")
    public Response updateDeviceParams(@RequestBody List<IotDevParams> datas) {
        int operatedResult = iotDevService.updateDeviceParams(datas);
        return Response.ok(operatedResult);
    }

    /**
     * 查询 后台 的数据日志表的是数据
     *
     * @param pageable
     * @param map
     * @return
     */
    @ResponseBody
    @PostMapping("entryDatas")
    public Response loadDataEntry(@PageableDefault Pageable pageable, @RequestParam Map map) {

        if (map.get("devId") == null || map.get("selectProp") == null) {
            return Response.error("请传入必须的设备ID和属性名称参数");
        }

        Page<Map> dbResult = iotDevService.loadDataEntry(pageable, map);

        return Response.ok(dbResult);
    }

    /**
     * 保存或更新数据
     *
     * @param map
     * @param map
     * @return
     */
    @ResponseBody
    @PostMapping("saveDataLogs")
    public Response saveDataLogs(@RequestParam Map map) {

        if (map.get("avalue") == null || map.get("theTime") == null) {
            return Response.error("请传入必要的数字");
        }

        int dataLogs = iotDevService.saveDataLogs(map);

        return Response.ok(dataLogs);
    }

    /**
     * 保存或更新数据
     *
     * @param map
     * @param map
     * @return
     */
    @ResponseBody
    @PostMapping("updDataLogs")
    public Response updDataLogs(@RequestParam Map map) {

        if (map.get("avalue") == null || map.get("theTime") == null) {
            return Response.error("请传入必要的数字");
        }

        int dataLogs = iotDevService.updateDataLogs(map);

        return Response.ok(dataLogs);
    }

    /**
     * 删除日志
     *
     * @param ids
     * @return
     */
    @ResponseBody
    @DeleteMapping("delDataLogs")
    public Response delDataLogs(@RequestBody Long[] ids) {

        iotDevService.delDataLogs(ids);

        return Response.ok();
    }

    @ApiOperation(value = "加载机房的设备ids", notes = "接口备注：无", produces = "application/json")
    @PostMapping("devids")
    public Response loadStationsIds (@ApiParam(value = "父级id") Long spaceId) {

        Map dbResult = iotDevService.loadStationsIds(spaceId);

        return Response.ok(dbResult);
    }

    @ApiOperation(value = "加载当前空间的子集空间的 设备ids", notes = "接口备注：无", produces = "application/json")
    @PostMapping("sondids")
    public Response loadStationsIdss (@ApiParam(value = "父级id") Long spaceId,@ApiParam(value = "类型") Integer type) {

        Map dbResult = iotDevService.loadStationsIdsd(spaceId,type);

        return Response.ok(dbResult);
    }

    @ApiOperation(value = "车间一级数据", notes = "接口备注：无")
    @PostMapping("workshopFirstLevelData")
    public Response workshopFirstLevelData (@ApiParam(value = "时间") String time,
                                            @ApiParam(value = "车间名称") String workSpaceName,
                                            @ApiParam(value = "能源名称") String name,
                                            @ApiParam(value = "数据类型")@RequestParam(value="selectType",defaultValue="total",required = true) String selectType) {
        if (!StringUtils.isNoneBlank(time, workSpaceName, name)){
            Response.error("传参有误！！请检查参数");
        }
        List dbResult = iotDevService.workshopFirstLevelData(time, workSpaceName, name, selectType);

        return Response.ok(dbResult);
    }

}
